home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dspgroup / asms.arc / FROM320.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-13  |  2.3 KB  |  104 lines

  1. #include <stdio.h>
  2. #include <memory.h>
  3. #include <process.h>
  4. #define    CONTROL 0x34
  5. #define    CONT2 0xb4
  6.     int inport, *storage[6];
  7.     char *malloc();
  8.     unsigned prt0,cntrlpt,prt1,prt2;
  9.     int prime,count,i,iter,y[50],baseio,seg320;
  10.     char name[20],buffer[24];
  11.     FILE *fp;
  12. main(argc,argv)
  13. int argc;
  14. char *argv[];
  15.     {
  16.     int k,value;
  17.     unsigned div;
  18.     long count;
  19.     float trate,osc,rate;
  20.     for (k=0;k<6;k++) storage[k]=(int *)malloc(0x8000);
  21.     baseio=0x300;
  22.     i=2;
  23.     osc = 5.0;
  24.     if (i == 2) 
  25.         osc = 6.25;
  26.     printf("Clock input = %f Mhz\n",osc);
  27.     osc = osc * 1.0e6;
  28.     cntrlpt = baseio + 7;
  29.     prt0 = baseio + 4;
  30.     prt2 = baseio + 6;
  31.     inp(cntrlpt);   /* halt */
  32.     spawnl(P_WAIT,"intel",argv[0],"gather","d000","300","0",NULL);
  33.     clark: do {
  34.         printf("Input desired sample rate in Hz ");
  35.         scanf( "%f",&rate);
  36.     } while ( (rate < 80.0 ) || (rate > 40000.1));
  37.     /* count gives you the oscillator "divisor" just as in SIO's */
  38.     count = osc/rate;
  39.     if ( count < 2 ) count += 1;
  40.     trate = osc /(float)count;
  41.     printf("\nRate = %f ",trate);
  42.     /* set timers for desired sampling rate */
  43.     control_timer(count,osc,&trate);
  44.     seg320=0xD000;
  45.     printf("\nDestination File Name ? ");
  46.             scanf("%s",name);
  47.             if( (fp =fopen(name,"wb")) == NULL ) {
  48.                        printf("file open error\n");
  49.                 exit();
  50.             }
  51.     inp(cntrlpt);
  52.     printf("\nHit any character when ready");
  53.     /* routine to check for a keyboard strike and to eat that char */
  54.     ci();
  55.     inp(prt2);    
  56.     for(k=0;k<6;k++) {
  57.         fulbuf(baseio,k);            /* read in data from 320 */
  58.     }
  59.     inp(cntrlpt);
  60.     for (k=0;k<6;k++) fwrite(storage[k],2,0x4000,fp);
  61.     fclose(fp);
  62. }
  63.  
  64. control_timer(cnt,osc,trate)
  65. long cnt;
  66. float *trate,osc;
  67. {
  68.     int ctl,cth;
  69.     /* tell board timer info coming */
  70.     outp(cntrlpt ,CONTROL);
  71.     /* count is timing divisor */
  72.     ctl = cnt & 0xff;    /* lo byte */
  73.     cth = ( cnt >> 8 ) & 0xff;/* hi byte */
  74.     /* control timer 0 */
  75.     outp(prt0 , ctl);
  76.     outp(prt0 , cth);
  77.     /* control timer 2 */
  78.     outp(cntrlpt , CONT2);
  79.     outp(prt2 , ctl);
  80.     outp(prt2 , cth);
  81.     /* compute new sampling rate  for output on screen*/
  82.     *trate = osc/(float)cnt;
  83. }
  84.  
  85. ci()
  86. {
  87.     int kbhit(),getch(),j;
  88.     while (kbhit()==0) {};
  89.       j=getch();
  90. }
  91.  
  92. fulbuf(baseio,which)
  93. int baseio,which;
  94. {
  95.     int i,j,porti;
  96.     j=-1;
  97.     porti=baseio+4;
  98.     for(i=0;i<0x4000;i++) {
  99.         while(inp(baseio+4)==j) {};
  100.         j=inp(porti);
  101.         *(storage[which]+i)=(inp(baseio+1)<<8)+inp(baseio);
  102.     }
  103. }
  104.